package com.example.parking.interfaces.http;

import com.example.parking.mq.RabbitConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/mq")
public class MqTestController {
    private final RabbitTemplate rabbitTemplate;

    public MqTestController(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    @PostMapping("/publish")
    @ResponseStatus(HttpStatus.ACCEPTED)
    public Map<String, Object> publish(@RequestParam String payload) {
        rabbitTemplate.convertAndSend(RabbitConfig.EXCHANGE, "sensor.gate", payload);
        return Map.of("status", "published");
    }
}


